package todolist.activities;

import java.util.List;

import todolist.activities.R;
import todolist.helpers.HelloItemizedOverlay;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MapViewActivity extends MapActivity implements OnClickListener {
	private Intent myIntent;
	private TextView tv;
	MyLocationOverlay myLocationOverlay;
	Button backButton;

	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.map);
		
		MapView mapView = (MapView) findViewById(R.id.mapview);
		//enable zooming
		mapView.setBuiltInZoomControls(true);
		
		// Add the buttons
        backButton = (Button) findViewById(R.id.map_back);
        backButton.setOnClickListener(this);
		
		myIntent = getIntent();
		Bundle extras = myIntent.getExtras();
		Double lat = extras.getDouble("lat");
		Double lng = extras.getDouble("lng");
		
		List<Overlay> mapOverlays = mapView.getOverlays();
		/* Get the marker */
		Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
		
		/* Create Geopoint - Set position of the androidmarker */
		GeoPoint gp = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
		
		/* Add the overlay (An overlay is just a layer you put over the map. In this case its just an android
		 * icon used to designate a task location. 
		 */
		HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);	
		OverlayItem overlayitem = new OverlayItem(gp, "Location", "description");
		itemizedoverlay.addOverlay(overlayitem);
		mapOverlays.add(itemizedoverlay);
	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.map_back:
			finish();
			break;
		}

	}
}